Hello, I am a beginner and I am so stumped with these two problems. The first one is, how do I get the output to look like this?
Enter the number of pods followed by
the number of peas in a pod:
22 10
22 pods and 10 peas per pod.
The total number of peas = 220
I have attempted for hours and so far I could only get the output to display this.
Enter the number of pods followed by
the number of peas in a pod:
This is what I wrote in my code.
import java.util.Scanner;
public class JavaApplication6 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of pods followed by");
System.out.println("the number of peas in a pod:");
int numberOfPods = keyboard.nextInt();
int peasPerPod = keyboard.nextInt();
int totalNumberOfPeas = numberOfPods*peasPerPod;
System.out.print(22 + " pods and ");
System.out.println(peasPerPod + " peas per pod.");
System.out.println("The total number of peas = "
+ totalNumberOfPeas);
}
}
I'm supposed to use a scanner for this, but the thing that gets me the most is how am I supposed to write the code that would display the numbers 22 and 10? I am having so many problems trying to get those two numbers to display.
Also, how do you output all the letters in a string to uppercase?
Like I'm trying to get a sentence to output in all uppercase letters but to no avail.
I used this code.
System.out.println("I like soda.");
String text = console.nextLine();
text.toUpperCase();
I used the above code but all I get is "I like soda." without that sentence returning in all uppercase letters.
If anyone can help me with these two problems it would be greatly appreciated. I'm sorry if I'm asking too much, I'm a beginner and I am so lost with this. Thank you.