|
Don't be angry.....
My problem is that I am not understanding that whether the source code I wrote is correct or not as the output is coming something else .I checked the code many times but still can't understand where the problem is.
So can you check my source code and correct it according to the question.
Hope you will understand now.
-- modified 5-Dec-20 21:01pm.
|
|
|
|
|
Tech Proof wrote: Don't be angry. I am not angry, I am just trying to get you to explain what the problem is. And just saying, "it does not work", or "the output is not correct", does not help us. You need to explain where the code is going wrong and why. We cannot be expected to build and debug the code in every question that gets posted here. Many of us have work of our own that takes priority.
|
|
|
|
|
OK, I am feeling generous, so here is part of the answer:
import java.io.*;
import java.util.*;
class Trig {
static double factorial(int number) {
double product = number;
while (--number > 0) {
product *= number;
}
return product;
}
static double sine(int angle) {
double radians = (Math.PI * angle) / 180.0;
double sum = radians;
boolean minus = true;
for (int power = 3; ; power += 2) {
double dividend = Math.pow(radians, power);
double divisor = factorial(power);
double quotient = dividend / divisor;
if (minus) {
sum -= quotient;
}
else {
sum += quotient;
}
minus = !minus;
if (power > 20)
break;
}
return sum;
}
public static void main(String[] argv) {
System.out.printf("sin(90) = %f\n", sine(90));
System.out.printf("sin(180) = %f\n", sine(180));
System.out.printf("sin(270) = %f\n", sine(270));
}
}
|
|
|
|
|
Quote: My problem is that I am not understanding that whether the source code I wrote is correct or not
Your code do not behave the way you expect, or you don't understand why !
There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Example 1:
Input : s ="()";
Output : true
Example 2:
Input: s = "() [] {}"
Output : true
Example 3:
Input : s = "(]"
Output : false
Example 4:
Input : s = "([)]"
Output : fasle
Example 5:
Input : s = "{[] }"
Output : true
The Condition should match s ="()" true condition. or s ="(" should return false … same for other conditions as well
|
|
|
|
|
OK, and do you have an actual question?
|
|
|
|
|
If you're looking for the code that evaluates enclosing brackets to validate they are matched up and nested correctly, that's not going to happen.
|
|
|
|
|
<pre>You are required to analyze the performance for Principles of Computer Programming subject
containing 135 students. Your program will prompt for final marks of each student, accumulate
the total and calculate the average. Display the average mark and the grade obtained based on
the information in Table 2 below. Design a pseudocode and write a full java program to provide
the solution.
Table 2: (Grade Category based on Average Mark)
--
Average mark range // Grade Category
Below 50 - Low
50 to 79 - Good
80 and above - Excellent </pre>
|
|
|
|
|
This is a very basic beginner program in any language. The whole intent is to learn with this. If this was an assignment you should attempt it yourself.
Pseduocode steps:
1. Take marks of a student as input
2. Calculate average of the input marks
3. Based on table 2 category, find the grade using average marks
4. Print the average and grades
5. Repeat step 1 to 4 for 135 students
Please try of. Post specific query if you face trouble. Don't forget to share what you tried and where you get stuck.
|
|
|
|
|
i tried but... im confused and slow and this def wrong
import java.util.*;
public class Mark {
public Mark () {
}
public static void main(String args[]) {
String grade;
int avgMark;
int studentMark;
Scanner input = new Scanner (System.in);
System.out.println(" Your Mark: ");
studentMark = input.nextInt();
avgMark = (total + finalMark) / 2
if(avgMark >= 80)
{
System.out.println("Grade: Excellent");
}
else if (avgMark >= 50 && avgMark <= 79) {
System.out.println(" Grade: Good ");
}
else if (avgMark <= 50) {
System.out.println(" Grade: Low ");
}
}
}
|
|
|
|
|
|
Hey guys so iam in a bit of a stump. Me and a friend have been working on a hard drive wiping software that is absolutely amazing. Well it turned out to be that way by chance.... It is in perfect working order... I was helping with Linux side of things. Anyways my friend has had a recent job change and is being bombarded with work. He is unable to help with the project anymore, considering he has a stake in the software and even gets paid, its kind of odd for him to take off. The software uses Linux command lines, udev, node.js, php, angular and batch for the core of its operation. It is by far the most advanced batch disk wiping software currently in development and has been in development for over a year.
I am looking for a skilled nodejs programmer and can give a break down of how the software works. I need help with the nodejs portion of the software. Anyone that is willing to devote some of their spare time will not be disappointed.
If there are any takers please go ahead and respond to me with your skype or discord info.
|
|
|
|
|
This site does not provide a free recruitment service. If you wish to advertise then please contact the sales department.
|
|
|
|
|
Hi there,
i upgraded the log4j 1.x to log4j2 2.12 Version and therefore changed the xml file.
Here is my log4j2.xml:
---------------------------------------------------
="1.0"="UTF-8"
<Configuration>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout>
<pattern>%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n</pattern>
</PatternLayout>
</Console>
<RollingFile name="DefaultAppender" fileName="../var/Project-server.log" filePattern="'.'yyyy-MM-dd">
<PatternLayout>
<pattern>%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n"</pattern>
</PatternLayout>
</RollingFile>
<RollingFile name="ErrorAppender" fileName=".../var/Project-server_error.log" filePattern="'.'yyyy-MM-dd">
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<pattern>%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n"</pattern>
</PatternLayout>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.mchange" level="WARN">
</Logger>
<Logger name="com.dwin.Project.common.util" level="WARN">
</Logger>
<Logger name="com.dwin.db" level="DEBUG">
</Logger>
<Logger name="com.dwin.util" level="DEBUG">
</Logger>
<Logger name="org.apache.cxf" level="WARN">
</Logger>
<Logger name="org.mortbay" level="WARN">
</Logger>
<Logger name="org.springframework" level="INFO">
</Logger>
<Root level="DEBUG">
<AppenderRef ref="DefaultAppender"/>
<AppenderRef ref="ErrorAppender"/>
<AppenderRef ref="ConsoleAppender"/>
</Root>
</Loggers>
</Configuration>
---------------------------------------------------
Here is the old log4j.xml 1.x:
---------------------------------------------------
="1.0"="UTF-8"
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n"/>
</layout>
</appender>
<appender name="DefaultAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="File" value="../var/Project-server.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n"/>
</layout>
</appender>
<appender name="ErrorAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="File" value="../var/Project-server_error.log"/>
<param name="threshold" value="ERROR"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss,SSS} %-5p [%t] %c [%X{request} %X{command}] - %m%n"/>
</layout>
</appender>
<logger name="com.mchange">
<level value="WARN"/>
</logger>
<logger name="com.dwin.Project.common.util">
<level value="WARN"/>
</logger>
<logger name="com.dwin.Project.server">
<level value="DEBUG"/>
</logger>
<logger name="com.dwin.db">
<level value="DEBUG"/>
</logger>
<logger name="com.dwin.util">
<level value="DEBUG"/>
</logger>
<logger name="org.apache.cxf">
<level value="WARN"/>
</logger>
<logger name="org.mortbay">
<level value="WARN"/>
</logger>
<logger name="org.springframework">
<level value="INFO"/>
</logger>
<root>
<level value="DEBUG"/>
<appender-ref ref="DefaultAppender"/>
<appender-ref ref="ErrorAppender"/>
<appender-ref ref="ConsoleAppender"/>
</root>
</log4j:configuration>
---------------------------------------------------
However i get the following error message when i execute my batch.file:
---------------------------------------------------
2020-10-16 15:40:26,373 main ERROR The parameter is null: policy
2020-10-16 15:40:26,377 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element RollingFile are invalid: field 'policy' has invalid value 'null'
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:208)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1002)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:942)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:934)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:552)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:241)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:288)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:579)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:651)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:668)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at com.dwin.Project.server.ProjectServer.<clinit>(ProjectServer.java:10)
2020-10-16 15:40:26,384 main ERROR The parameter is null: policy
2020-10-16 15:40:26,385 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element RollingFile are invalid: field 'policy' has invalid value 'null'
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:208)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1002)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:942)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:934)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:552)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:241)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:288)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:579)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:651)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:668)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at com.dwin.Project.server.ProjectServer.<clinit>(ProjectServer.java:10)
2020-10-16 15:40:26,388 main ERROR Null object returned for RollingFile in Appenders.
2020-10-16 15:40:26,389 main ERROR Null object returned for RollingFile in Appenders.
2020-10-16 15:40:26,398 main ERROR Unable to locate appender "DefaultAppender" for logger config "root"
2020-10-16 15:40:26,399 main ERROR Unable to locate appender "ErrorAppender" for logger config "root"
---------------------------------------------------
Can someone help?
|
|
|
|
|
org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element RollingFile are invalid: field 'policy' has invalid value 'null'
Check your code to see why this value is null.
|
|
|
|
|
I am trying to convert a JAVA POJO object with a JsonObject to a String as following:
class MyPojo {
public MyPojo(String sName, JsonObject obj)
{
this.sName = sName;
this.tJsonObj = obj;
}
public String sName;
public javax.json.JsonObject tJsonObj;
};
javax.json.JsonObject jsonObj = JsonUtils.toJsonObject("{\"key\": 123}");
ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper.ObjectMapper();
JsonNode node = mapper.valueToTree(new MyPojo("myname", jsonObj));
String jsonStr = node.toString();
I am getting jsonStr value as:
{"sName":"myname","tJsonObj":{"key":{"integral":true,"valueType":"NUMBER"}}}
How can I get jsonStr value as:
{"sName":"myname","tJsonObj":{"key":123}}
JsonUtils.toJsonObject is my own utility method to get JsonObject from String .
|
|
|
|
|
Hi guys I created a project in android studio which has 2 types of login system the
1. Sign in with email and password
2. Login with phone number
I have a problem in login with phone number
I have 3 activities in project which in
1. I am taking the the login with email and password
2. Is I am taking the login with phone number
3. I am checking if the email is verified or not
So if the email is verified the person can go to app inside
But when I login with phone number it go to the 3rd activitiy to the email verification but I want it go to the app not to the verify email activity
Here is my code for main activity
----------
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
myViewPager = (ViewPager) findViewById(R.id.main_tabs_pager);
myTabsaccessorAdopter = new TabsAccessorAdopter(getSupportFragmentManager());
myViewPager.setAdapter(myTabsaccessorAdopter);
myTabLayout = (TabLayout) findViewById(R.id.main_tabs);
myTabLayout.setupWithViewPager(myViewPager);
}
@Override
protected void onStart()
{
super.onStart();
if (currentUser == null)
{
SendUserToLoginActivity();
}
else
{
if(!currentUser.isEmailVerified())
{
SendUserToVerifyEmailActivity();
}
}
}
private void SendUserToLoginActivity()
{
Intent loginIntent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(loginIntent);
}
private void SendUserToVerifyEmailActivity()
{
Intent verifyEmailIntent = new Intent(MainActivity.this,VerifyEmailActivity.class);
startActivity(verifyEmailIntent);
}
private void SendUserToMainActivity()
{
Intent mainIntent = new Intent(MainActivity.this,MainActivity.class);
startActivity(mainIntent);
}
}
-------------------------------
And here is my PHone login code
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register__with__phone__number_);
mAuth =FirebaseAuth.getInstance();
loadingBar = new ProgressDialog(this);
Initialize();
Second_Fourth.registerCarrierNumberEditText(Second_Fifth);
First_Fifth.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String code = First_Fourth.getSelectedCountryCode();
First_Layout.setVisibility(View.INVISIBLE);
Second_Layout.setVisibility(View.VISIBLE);
Third_Layout.setVisibility(View.INVISIBLE);
Second_Fourth.setCountryForPhoneCode(Integer.parseInt(code));
}
});
Second_Seven.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String phoneNumber = Second_Fifth.getText().toString();
phoneNumber = Second_Fourth.getFullNumberWithPlus();
if(TextUtils.isEmpty(phoneNumber))
{
Toast.makeText(Register_With_Phone_Number_Activity.this, "Number is recquired", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Phone verification");
loadingBar.setMessage("please wait...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(phoneNumber,60,TimeUnit.SECONDS,Register_With_Phone_Number_Activity.this,mCallbacks);
}
}
});
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks()
{
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential)
{
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e)
{
Toast.makeText(Register_With_Phone_Number_Activity.this, "Invalid phone number", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
First_Layout.setVisibility(View.INVISIBLE);
Second_Layout.setVisibility(View.VISIBLE);
Third_Layout.setVisibility(View.INVISIBLE);
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
super.onCodeSent(s, forceResendingToken);
loadingBar.dismiss();
mVerificationId = s;
mResendToken = forceResendingToken;
First_Layout.setVisibility(View.INVISIBLE);
Second_Layout.setVisibility(View.INVISIBLE);
Third_Layout.setVisibility(View.VISIBLE);
}
};
Second_Eight.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
SendUserToRegisterNumberActivity();
}
});
Third_Fourth.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String verificationcode = Third_Third.getText().toString();
if (verificationcode.isEmpty())
{
Toast.makeText(Register_With_Phone_Number_Activity.this, "Verification code first", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("verification code");
loadingBar.setMessage("please wait...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId,verificationcode);
signInWithPhoneAuthCredential(credential);
}
}
});
}
private void signInWithPhoneAuthCredential(final PhoneAuthCredential credential)
{
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if (task.isSuccessful())
{
loadingBar.dismiss();
Toast.makeText(Register_With_Phone_Number_Activity.this, "Logged in Successful", Toast.LENGTH_SHORT).show();
SendUserToMainActivity();
}
else
{
loadingBar.dismiss();
Toast.makeText(Register_With_Phone_Number_Activity.this, "Error", Toast.LENGTH_SHORT).show();
}
}
});
}
private void Initialize()
{
First_Layout = (LinearLayout) findViewById(R.id.first_layout);
Second_Layout = (LinearLayout) findViewById(R.id.second_layout);
Third_Layout = (LinearLayout) findViewById(R.id.third_layout);
First_Fifth = (Button) findViewById(R.id.first_fifth);
Second_Seven = (Button) findViewById(R.id.second_seven);
Second_Eight = (Button) findViewById(R.id.second_eight);
Third_Fourth = (Button) findViewById(R.id.third_fourth);
First_Fourth = (CountryCodePicker) findViewById(R.id.first_fourth);
Second_Fourth = (CountryCodePicker) findViewById(R.id.second_fourth);
Second_Fifth = (EditText) findViewById(R.id.second_fifth);
Third_Third = (EditText) findViewById(R.id.third_third);
}
private void SendUserToRegisterNumberActivity()
{
Intent registernumberIntent = new Intent(Register_With_Phone_Number_Activity.this,Register_With_Phone_Number_Activity.class);
startActivity(registernumberIntent);
}
private void SendUserToMainActivity()
{
Intent mainIntent = new Intent(Register_With_Phone_Number_Activity.this,MainActivity.class);
startActivity(mainIntent);
}
}
|
|
|
|
|
3. Modify the code from the last week’s theoretical lecture (HelloWorldPanel,
HelloWorldFrame) to make a frame and a panel that show your full name
at each corner of the frame. Let the names be (MyNamePanel,
MyNameFrame) and choose whatever formats you want.
|
|
|
|
|
We didn't attend that lecture so can't really help you with your homework
|
|
|
|
|
|
servlet problem and mapping with sql
server issues
|
|
|
|
|
if anybody have soltution tell me its urgent please
|
|
|
|
|
Member 14941356 wrote: servlet problem and mapping with sql
You have hardly shared about what you are doing and the issue faced.
Please look at the forum guidelines: Java Discussion Boards
|
|
|
|
|
|
You haven't described any kind of problem so there is no way anyone is going to be able to tell you what's wrong.
You might want to start by reading this: Asking questions is a skill[^]
|
|
|
|