Texts: I need guidance in resolving this code in Java to help me further understand how to solve it.
import java.util.Scanner;
public class Oranges {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numOranges;
System.out.print("She sold me: ");
numOranges = scnr.nextInt();
System.out.println("oranges.");
}
}
CHALLENGE ACTIVITY 1.1.2: Programming basics
First, write code that uses scnr.nextInt() to read in a value for numOranges from input.
Then, write code that uses System.out.println() to output 'She sold me ', the variable numOranges, and ' oranges.'
Ex: If the input is 8, then the output is:
She sold me 8 oranges.
Ex: If the input is 3, then the output is:
She sold me 3 oranges.
1 import java.util.Scanner;
2 public class Oranges {
3 public static void main(String[] args) {
4 Scanner scnr = new Scanner(System.in);
5 int numOranges;
6 System.out.print("She sold me ");
7 numOranges = scnr.nextInt();
8 System.out.println("oranges.");
9 }
10 }