|
|
package exercise12;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Exercise12 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String ticket="";
String temp;
int Ticket, Remainder;
char[] numb=new char[6];
System.out.print("Please enter the ticket number : ");
temp= String.valueOf(input.nextInt());
Boolean answer;
for(int i=0; i<6;i++){
numb[i]=temp.charAt(i);
if (i != 5){ticket=ticket+numb[i]; }
}
Ticket=Integer.parseInt(ticket);
temp=String.valueOf(numb[5]);
Remainder=Integer.parseInt(temp);
if (Ticket%7==Remainder){answer=true;
}
else{answer=false;
}
JOptionPane.showMessageDialog(null,answer.toString().toUpperCase());
}
}
modified 5-Mar-15 3:08am.
|
|
|
|
|
This looks more complex than it needs to be. If I understand correctly you want to verify that the last digit equals the remainder when the 5-digit value is divided by 7, which could be something like:
int ticket = input.nextInt();
int remainder = ticket % 10;
ticket /= 10;
int modulo = ticket % 7;
if (modulo == remainder)
|
|
|
|
|
thanks dude,,, it was really helpful
|
|
|
|
|
Below is my procedure signature:
PROCEDURE sp_trx(i_arr_Sust IN T_TAB_SUST,
o_locator_map OUT SYS_REFCURSOR,
o_pkid_map OUT SYS_REFCURSOR,
o_error OUT VARCHAR2)
And below is my ref cursor inside procedure:
OPEN o_locator_map FOR
SELECT c_uuid,
c_id,
r_locator,
TO_CHAR(cj_creation_date, g_dt_format) c_date,
TO_CHAR(cj_last_modified_date, g_dt_format) cj_last_modified_date,
version_number
FROM tmp_locator_map;
Below is data type in oracle:
c_uuid-->VARCHAR2(50 BYTE), c_id--> NUMBER, r_locator--> VARCHAR2(10 BYTE)
And below is my Java process for procedure:
String insertStoreProc = "{call PKG_LOADER.sp_trx(?,?,?,?)}";
CallableStatement callableStatement = con.prepareCall(insertStoreProc);
callableStatement.setObject(1, returninParam, 2003);
callableStatement.registerOutParameter(2, OracleTypes.CURSOR);
callableStatement.registerOutParameter(3, OracleTypes.CURSOR);
callableStatement.registerOutParameter(4, java.sql.Types.VARCHAR);
callableStatement.execute();
ResultSet rset =((OracleCallableStatement) callableStatement).getCursor(2);
while (rset.next()){
String c_uuid = rset.getString(1);
}
Now Problem is i'm getting below mention exception at rset.next():
java.sql.SQLException: ORA-08103: object no longer exists
Kindly suggest. Thanks in advance
modified 2-Mar-15 7:35am.
|
|
|
|
|
Presumably the value of rset is null, or does not contain any items. This is really a database issue, nothing to do with Java.
|
|
|
|
|
It's working fine in non-multithreading environment.
But when I switch to Multi-Threading environment, problem get start. When I call this procedure in multithreading, we are not able to find anything in resultset. Even I have tried with Spring JdbcTemplate and SimpleJdbcCall as well, but not able to get any break through.
|
|
|
|
|
The only way to find out what is happening is to use the debugger, or add some logging code to your application. If this only happens in multi-threading then you probably have a synchronisation issue somewhere.
|
|
|
|
|
I want to read JSON file from disk and want to convert it into byteArray[] object in java.
|
|
|
|
|
And what problem are you having with this? You do understand that a file is a byte array, so you need to be a bit more detailed about what you are trying to achieve.
BTW I deleted your duplicate of this question.
|
|
|
|
|
Strange, mostly people would want to convert the data to a custom object.
Anyways, this link[^] must be helpful, if you're willing to make such function in your application.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I keep receiving an error massage that I am missing my main method. How do I correct it, any help.
package display;
}
class MathOP{
double num1;
double num2;
double mathadd(){
return num1 + num2;
}
double mathsub(){
return num1 -num2;
}
void setVal(double x, double y) {
num1 = x;
num2 = y;
}
}
class MathOP2 extends MathOP {
double mathadd(){
return num1 + num2;
}
double mathsub(){
return num1 -num2;
}
double mathmul(){
return num1 * num2;
}
double mathdiv(){
return num1 / num2;
}
class display extends MathOP2 {
display() {
System.out.println("MathAdd");
System.out.println("MathSub");
System.out.println("MathMul");
System.out.println("MathDiv");
}
}
}
|
|
|
|
|
Remove "}" after package.
|
|
|
|
|
The packages having class without a Main function are more like a library package. Are you sure you don't want to have a Main function?
You can create a seperate class (maybe inside the same package) and then add the Main function inside it
package packagename;
public class MainClass {
public static void Main(String[] args) {
System.out.println("Hello world!");
}
}
This would be executed as the first function, and you can set it to the default entry point. Which IDE are you using? NetBeans or eclipse?
Main function is the entry point; set by you in properties, and it the very first function to be executed by the application. That is why it is required.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I am using jgrasp. Thanks for responding to my post
|
|
|
|
|
This is your third question on this subject, and reinforces my view that you really should follow the link I gave you to the Java Tutorials, and work through them carefully. You are posting a lot of code which does not really fit together in any useful way, so the chances of you stumbling across a working solution are not very high. Posting questions like this is not a good way to learn programming.
|
|
|
|
|
Can someone see where I am getting it wrong, I could not get this code to compile.
class MathOP{
double num1;
double num2;
//create a method mathadd
double mathadd(){
return num1 + num2;
}
// create a method mathsub
double mathsub(){
return num1 -num2;
}
//set value of mathop for test
void setVal(double x, double y) {
num1 = x;
num2 = y;
}
}
// Here MathOP is extended to include multiply and division
class MathOP2 extends MathOP {
double mathadd(){
return num1 + num2;
}
double mathsub(){
return num1 -num2;
}
double mathmul(){
return num1 * num2;
}
double mathdiv(){
return num1 / num2;
}
/************************
Name:
Program
Date:
Purpose:
**************************/
class MathOP{
public static void main(String args[]) {
double num1, num2;
//the try exception is put her to monitor the block of code
try{
double num1 = 0;
double num2 = 5.5/num1;
System.out.println("Division by zero " is + num2");
// Catch exception is to catch the exception from above
}catch (ArithmeticException e){
System.out.println(("Division by zero ") is; + e");
}
System.out.println("After catch statement.");
}
}
boolean Y = true;
System.out.println("Do you want to exist (Y/N)?");
}finally{
if (Y) {
System.out.println("Thanks for using our system");
}else{
System.out.println("run the program again");
}
}
|
|
|
|
|
Please do not repost the same question.
|
|
|
|
|
Please can someone assist in debug the below code. I am trying to add multiply and division method to the code whereby both methods can accepts two parameters and return a value.
class MathOP{
double num1;
double num2;
//create a method mathadd
double mathadd(){
return num1 + num2;
}
// create a method mathsub
double mathsub(){
return num1 -num2;
}
//set value of mathop for test
void setVal(double x, double y) {
num1 = x;
num2 = y;
}
}
/************************
This is a flower box
Name:
Program name:
Date:
Purpose:
**************************/
class TestMathOP {
public static void main (String args[]) {
MathOP mytest1 = new MathOP();
MathOP mytest2 = new MathOP();
MathOP mytest3 = new MathOP();
double Mathadd;
double Mathsub;
double Mathadd1;
//intitialize each text
mytest1.setVal(5.5, 7.5);
mytest2.setVal(5.5, 7.5);
mytest3.setVal(5.5, 7.5);
//get values
Mathadd = mytest1.mathadd();
System.out.println("The sum of two number is " + Mathadd);
//get values of subtraction
Mathsub = mytest2.mathsub();
System.out.println("The subtraction of two number is " + Mathsub);
boolean Y = true;
System.out.println("Do you want to exist (Y/N)?");
if (Y) {
System.out.println("Thanks for using our system");
}else{
System.out.println("run the program again");
}
}
//Modify the code to prompt for the operation
class TestMathOP1 {
void main (String args[]) {
MathOP mytest3 = new MathOP();
double Mathadd1;
Mathadd1 = mytest3.mathadd();
System.out.println("Enter operator + " + Mathadd1);
System.out.println("Do you want another operation (Y/N)?");
}
}
}
modified 23-Feb-15 20:40pm.
|
|
|
|
|
what u want, i didn't understand bro, your code is running well except run the program again.. call
if u have problem then specify correctly
|
|
|
|
|
I can seem to get the other part of the class to run. I mean after the "run the program again".
|
|
|
|
|
double mathadd(){
return num1 + num2;
}
Your methods should accept local parameters rather than having some other method set them in advance, as shown below:
double mathadd(double num1, double num2) {
return num1 + num2;
}
The same with the subtraction method. You then call it with a stament like:
double result = mytest1.mathadd(5.5, 7.12);
The setval method is redundant and should not be used. You also need to import the MathOP class into your test application, rather than trying to define them in your source.
Take a look at http://docs.oracle.com/javase/tutorial/java/index.html[^] for a more detailed explanation of how to write Java.
|
|
|
|
|
Thanks for responding to my post but I am still have issue compiling the code. Can you see what I am doing wrong in the below code?
package display;
class MathOP{
double num1;
double num2;
double mathadd(){
return num1 + num2;
}
double mathsub(){
return num1 -num2;
}
class MathOP2 extends MathOP {
double mathmul(){
return num1 * num2;
}
double mathdiv(){
return num1 / num2;
}
MathOP2 objMath = new MathOP2();
double return = objMath.mathadd(5.5,5.12);
System.out.println("MathAdd" + Mathadd);
double return = objMath;mathsub(42.0,20.2);
System.out.println("MathSub" + Mathsub);
double return = objMath;mathdiv(60.3,20.2);
System.out.println("MathMul" + Mathmul);
double return = objMath;mathmult(10.4,5.4);
System.out.println("MathDiv" + Mathdiv);
}
}
|
|
|
|
|
Your methods in MathOP and MathOP2 are not using method parameters. They should be of the form:
double mathadd(double num1, double num2){
return num1 + num2;
}
As I suggested in my previous message, you should go and work through the Java tutorials.
|
|
|
|
|
//solv by akshgods
/*
i deleted many thing which is not required in your program,
so always try to make simple and easy dear.
sorry for late reply
*/
package javaapplication8;
import java.util.*;
class MathOP{
//create a method mathadd
double mathadd(double a,double b){
return a+b;
}
// create a method mathsub
double mathsub(double x,double z){
return x-z;
}
}
//TestMathOp class
class TestMathOP {
public static void main (String args[])
{
MathOP mytest1 = new MathOP();
MathOP mytest2 = new MathOP();
double add;
double sub;
/*
scanner class for taking integer input
*/
Scanner sc=new Scanner(System.in);
int f=0;
while(f==0)//while for reapitation of program
{
add = mytest1.mathadd(5.5,7.5);
System.out.println("The sum of two number is " +add);
//get values of subtraction
sub = mytest2.mathsub(5.5,7.5);
System.out.println("The subtraction of two number is " +sub);
System.out.println("Do you want to exist (Y=1/N=0)?");
f=sc.nextInt();//here we are taking value from keybord 1 or 0 for exit or reapeat programm
if (f==1)
{
System.out.println("Thanks for using our system");
break;
}
else
{
System.out.println("run the program again");
}
}
}
}
|
|
|
|