java question, my questions are in the following codes with comments, just answer next or under it thanks!
theres only few, so no worry.
import java.security.SecureRandom;
public class clsTestRand {
public static void main(String[] args) {
// TODO Auto-generated method
stub
//int num1, num2, num3, num4, num5,
num6;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
SecureRandom rn = new
SecureRandom(); /
for (int i= 1; i<=10; i++) // so
random numbers between 1 to 10 right?
{
int roll =1
+rn.nextInt(6);// add 1 because it does not count 6, count from 0
(this one isn't question, we are just assuming that this is a
dice)
switch
(roll)
{
case 1:
++num1; // why do we use ++ ? and what it
does?
break;
case 2:
++num2;
break;
case 3:
++num3;
break;
case 4:
++num4;
break;
case 5:
++num5;
break;
}//end
switch
}//end for loop
System.out.println("1: "+num1); //
+num1 using println was equal to printf %d%n, so I guess it's just
different way right? so it's like " : " + variable + variable if we
want more than 1 variable if we need it inside println?
System.out.printf("2: %d%n",
num2);
System.out.printf("3: %d%n",
num3);
System.out.printf("4: %d%n",
num4);
System.out.printf("5: %d%n",
num5);
}
}
import java.security.SecureRandom;
public class clsTestRand {
public static void main(String[] args) {
// TODO Auto-generated method
stub
//int num1, num2, num3, num4, num5,
num6;
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
SecureRandom rn = new
SecureRandom(); /
for (int i= 1; i<=10; i++) // so
random numbers between 1 to 10 right?
//NO its not
random number between 1 and 10, It repeats following statements
within the block 10 times, so to generate 10 //random numbers and
do operations on them
{
int roll =1
+rn.nextInt(6);// add 1 because it does not count 6, count from 0
(this one isn't question, we are just assuming that this is a
dice)
switch
(roll)
{
case 1:
++num1; // why do we use ++ ? and what it
does?
//++num1 is
pre increment operator,it increases the value of num1 by 1 and then
assigns it.
break;
case 2:
++num2;
break;
case 3:
++num3;
break;
case 4:
++num4;
break;
case 5:
++num5;
break;
}//end
switch
}//end for loop
System.out.println("1: "+num1); //
+num1 using println was equal to printf %d%n, so I guess it's just
different way right? so it's like " : " + variable + variable if we
want more than 1 variable if we need it inside println?
//println("1: "+num1) is like printf("1: %d",num1)....to print
more than one variable in println, use println(" "+num1+" "+num2+"
//"+num3)
System.out.printf("2: %d%n",
num2);
System.out.printf("3: %d%n",
num3);
System.out.printf("4: %d%n",
num4);
System.out.printf("5: %d%n",
num5);
}
}
java question, my questions are in the following codes with comments, just answer next or under...
JAVA I need a switch so that users can input one selection then another. These selections are for a simple calculator that uses random numbers 1. + 2. - 3. * 4./ 5. RNG. This has to be simple this is a beginners class. Here is what I have import java.util.Scanner; import java.util.Random; import java.util.*; public class You_Michael02Basic_Calculator { public static void main(String[] args) { // Generate random numbers int num1,num2; num1 =(int)(Math.random()*100+1);...
What I need: Create a new program named Reverse4 and declare four integer variables with the values 23, 45, 55, and 67. Add a method named Reverse that reverses the positions of four integer variables. The Reverse method should accept the variables as references. Write a Main() method that displays the four variables both before and after reversing them to ensure the method works correctly. What I have: using System; class Reverse4 { public static void reverse(ref int num1, ref...
Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...
Must be written in JAVA Code Modify Fig. 19.2 to use recursive method recursiveLinear-Search to perform a linear search of the array. The method should receive the search key and starting index as arguments. If the search key is found, return its index in the array; otherwise, return –1. Each call to the recursive method should check one index in the array. Figure 19.2 import java.security.SecureRandom; import java.util.Arrays; import java.util.Scanner; public class LinearSearchTest{ public static int linearSearch(int data[], int searchKey)...
How convert this c++ into C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int num1; int c, num2, ans; cout<<"Enter difficulty level(1/2)\n"; cin>>c; if(c==1) { num1= rand() % 10; num2= rand() % 10; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No. Please try again.\n"; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; } } } else if(c==2) { num1= rand() % 10+90; num2= rand() % 10+90; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No. Please...
How to convert C++ code to C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int num1; int c, num2, ans; cout<<"Enter difficulty level(1/2)\n"; cin>>c; if(c==1) { num1= rand() % 10; num2= rand() % 10; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No. Please try again.\n"; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; } } } else if(c==2) { num1= rand() % 10+90; num2= rand() % 10+90; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No....
Java debugging in eclipse
package edu.ilstu;
import java.util.Scanner;
/**
* The following class has four independent debugging
* problems. Solve one at a time, uncommenting the next
* one only after the previous problem is working correctly.
*/
public class FindTheErrors {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
/*
* Problem 1 Debugging
*
* This problem is to read in your first name,
* last name, and current year and display them in
*...
question of java , very simple one written under with comment, just reply next or below it, thanks public static void main(String[] args) { // TODO Auto-generated method stub int i, j; final int ARRAY_LENGTH = 5; int[] myArray = new int[ARRAY_LENGTH]; for(i=0; i< myArray.length; i++) { myArray[0] += 2; } for(j = 0; j ...
#include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...
I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...